<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:确认弹出窗组件
* @fileName:LaniusPopConfirm.vue
* @author:zoujunjie
* @date:2022-05-17
* 用法：用法和Element Plus PopConfirm类似
!-->
<template>
  <el-popover
    effect="dark"
    trigger="click"
    popper-class="lanius-pop-confirm"
    ref="popoverRef"
    :disabled="disabled"
    :placement="placement"
  >
    <div class="lanius-pop-confirm-slot">
      <div class="title">
        <el-image :src="warningIcon" class="icon"></el-image>
        {{ title }}
      </div>
      <div class="content">{{ content }}</div>
      <div class="buttons" style="">
        <el-button size="small" @click="onConfirmClick">{{
          confirmText
        }}</el-button>
        <el-button size="small" @click="onCancelClick">{{
          cancelText
        }}</el-button>
      </div>
    </div>

    <template #reference>
      <slot />
    </template>
  </el-popover>
</template>

<script lang="ts" setup>
import warningIcon from "@/assets/img/common/warning.png";
import { toRefs, ref, unref } from "vue";

interface Props {
  title: string;
  content: string;
  confirmText?: string;
  cancelText?: string;
  disabled?: boolean;
  placement?: string;
}

interface Emits {
  (e: "confirm"): void;
  (e: "cancel"): void;
}

const popoverRef = ref();

const props = withDefaults(defineProps<Props>(), {
  confirmText: "确认",
  cancelText: "取消",
  disabled: false,
  placement: "top",
});

const emits = defineEmits<Emits>();

const onConfirmClick = () => {
  emits("confirm");
  popoverRef.value.hide();
  unref(popoverRef);
};

const onCancelClick = () => {
  emits("cancel");
  popoverRef.value.hide();
  unref(popoverRef);
};

const { title, content, confirmText, cancelText, disabled, placement } =
  toRefs(props);
</script>

<style lang="scss">
.lanius-pop-confirm.el-popover.el-popper {
  min-width: 410px;
  padding: 10px;
}
.lanius-pop-confirm-slot {
  min-height: 100px;
}
.lanius-pop-confirm-slot .title {
  font-size: 20px;
  font-weight: 700;
  line-height: 28px;
  display: flex;
  align-items: center;
  padding-top: 5px;
  margin-left: 5px;
}
.lanius-pop-confirm-slot .title .icon {
  margin-right: 15px;
  width: 25px;
  height: 22px;
}

.lanius-pop-confirm-slot .content {
  font-size: 14px;
  line-height: 20px;
  margin-left: 40px;
  margin-top: 6px;
}
.lanius-pop-confirm-slot .buttons {
  text-align: right;
  margin-top: 15px;
}
</style>
